﻿from django import newforms as forms
from google.appengine.api import users
import models
from google.appengine.ext.db import djangoforms
from app.functions.funcs import split_tags,parsetext

PLAYER_RACE_CHOICES = (
	('Human', 'Human'),
	('Gnome', 'Gnome'),
	( 'Draenei', 'Draenei'),
	('NightElf', 'NightElf'),
	('Dwarf', 'Dwarf'),
	( 'Orc', 'Orc'),
	('Undead', 'Undead'),
	('Troll','Troll'),
	('Tauren','Tauren'),
	('BloodElf','BloodElf'))

PLAYER_GENDER_CHOICES = (('2','Boy'),('3','Girl'))

PLAYER_CLASS_CHOICES = (('WARLOCK','WARLOCK'),
						('PRIEST','PRIEST'),
						('WARRIOR','WARRIOR'),
						('SHAMAN','SHAMAN'),
						('ROGUE','ROGUE'),
						('PALADIN','PALADIN'),
						('MAGE','MAGE'),
						('HUNTER','HUNTER'),
						('DRUID','DRUID'))
						
ACTION_KINDS = (('reward','reward'),
                ('punishment','punishment'),
                ('bosskill','bosskill'),
                ('adjust','adjust'))

class EventForm(forms.Form):
	title = forms.CharField()
	summary = forms.CharField()
	content = forms.CharField(widget=forms.Textarea(),required=False)
	start = forms.DateTimeField(required=False)
	end = forms.DateTimeField(required=False)

	def save(self):
		data = models.EventData(
							title=self.clean_data['title'],
							summary=self.clean_data['summary'],
							content=self.clean_data['content'],
							start = self.clean_data['start'],
							end = self.clean_data['end'],
							)
		data.put()
	def edit(self,event):
		event.title=self.clean_data['title']
		event.summary=self.clean_data['summary']
		event.content=self.clean_data['content']
		event.start = self.clean_data['start']
		event.end = self.clean_data['end']
		event.put()

class PlayerForm(forms.Form):
	player_name = forms.CharField()
	player_class = forms.ChoiceField(choices=PLAYER_CLASS_CHOICES)
	player_race = forms.ChoiceField(choices=PLAYER_RACE_CHOICES)
	player_sex = forms.ChoiceField(choices=PLAYER_GENDER_CHOICES)
	player_guild = forms.CharField(required=False)
	player_level = forms.CharField(required=False)

	def save(self):
		player = models.Players(
							player_name=self.clean_data['player_name'],
							player_race=self.clean_data['player_race'],
							player_class=self.clean_data['player_class'],
							player_guild=self.clean_data['player_guild'],
							player_sex=self.clean_data['player_sex'],
							player_level=self.clean_data['player_level'],
							author=current_user)
		self.player_put()

	def edit(self,data):
		data.player_name=self.clean_data['player_name']
		data.player_class=self.clean_data['player_class']
		data.player_race=self.clean_data['player_race']
		data.player_guild=self.clean_data['player_guild']
		data.player_sex=self.clean_data['player_sex']
		data.player_level=self.clean_data['player_level']
		data.player_put()

class GearForm(forms.Form):
	gear_name = forms.CharField()
	gear_id = forms.CharField()
	gear_icon = forms.CharField()
	gear_class = forms.CharField()
	gear_subclass = forms.CharField()
	gear_color = forms.CharField()
	gear_count = forms.CharField()
	gear_player = forms.CharField()
	gear_costs = forms.CharField()
	gear_time = forms.CharField()
	gear_zone = forms.CharField()
	gear_boss = forms.CharField()
	gear_tooltip = forms.CharField()
	gear_note = forms.CharField()

	def save(self,event):
		update_costs = self.clean_data['gear_costs']-self.gear_costs
		data = models.EventData(
							event=event,
							gear_name=self.clean_data['gear_name'],
							gear_id=self.clean_data['gear_id'],
							gear_icon=self.clean_data['gear_icon'],
							gear_class=self.clean_data['gear_class'],
							gear_subclass=self.clean_data['gear_subclass'],
							gear_color=self.clean_data['gear_color'],
							gear_count=self.clean_data['gear_count'],
							gear_player=self.clean_data['gear_player'],
							gear_costs=self.clean_data['gear_costs'],
							gear_time=self.clean_data['gear_time'],
							gear_zone=self.clean_data['gear_zone'],
							gear_boss=self.clean_data['gear_boss'],
							gear_tooltip=self.clean_data['gear_note'],
							gear_note=self.clean_data['gear_boss'])
		data.gear_put()
	def edit(self,gear):
		update_costs = self.clean_data['gear_costs']-self.gear_costs
		gear_name=self.clean_data['gear_name']
		gear_id=self.clean_data['gear_id']
		gear_icon=self.clean_data['gear_icon']
		gear_class=self.clean_data['gear_class']
		gear_subclass=self.clean_data['gear_subclass']
		gear_color=self.clean_data['gear_color']
		gear_count=self.clean_data['gear_count']
		gear_player=self.clean_data['gear_player']
		gear_costs=self.clean_data['gear_costs']
		gear_time=self.clean_data['gear_time']
		gear_zone=self.clean_data['gear_zone']
		gear_boss=self.clean_data['gear_boss']
		gear_tooltip=self.clean_data['gear_note']
		gear_note=self.clean_data['gear_boss']		
		gear.gear_put()